package com.yjhealth.libs.core.core.activity;

import android.view.LayoutInflater;
import android.view.View;

import com.qmuiteam.qmui.arch.QMUIFragment;
import com.qmuiteam.qmui.arch.QMUIFragmentActivity;
import com.qmuiteam.qmui.widget.QMUIWindowInsetLayout;

public abstract class CoreQmuiActivity extends QMUIFragmentActivity {
    @Override
    protected int getContextViewId() {
        return -1;
    }

    @Override
    public void onBackPressed() {
        QMUIFragment fragment = getCurrentFragment();
        if (fragment != null && !fragment.isInSwipeBack()) {
            super.onBackPressed();
        } else {
            finish();
        }
    }

    /**
     * fitsSystemWindows=true 时，QMUIFragmentActivity 里的 padding 会失效，统一在 setContentView 里加上 QMUIWindowInsetLayout
     * 当 QMUIFragmentActivity 使用fragment模式的情况下不考虑
     * 使用databinding的模式下也不考虑
     * 请不要调用其他的 setContentView 重载方法
     *
     * @param layoutResID
     */
    @Override
    public void setContentView(int layoutResID) {
        if (getContextViewId() > 0) {//fragment模式
            super.setContentView(layoutResID);
        } else if (dataBindingMode()) {
            super.setContentView(layoutResID);
        } else {
            QMUIWindowInsetLayout insert = new QMUIWindowInsetLayout(this);
            View view = LayoutInflater.from(this).inflate(layoutResID, insert, true);
            setContentView(view);
        }
    }

    public boolean dataBindingMode() {
        return false;
    }
}
